package com.itcam.cm.manager.test;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.read.listener.ReadListener;

import java.util.ArrayList;
import java.util.List;

public class StudentReadListener extends AnalysisEventListener<Student> {

    // 批处理
    List<Student> list = new ArrayList<>();

    @Override
    public void invoke(Student student, AnalysisContext analysisContext) {
        list.add(student);
        if(list.size()>=5){
            System.out.println("每读取5行都读到一个student");
            System.out.println(list);
            System.out.println("每读取5行都插入一次数据库");
            list.clear();
        }

    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        System.out.println("doAfterAllAnalysed...收尾方法");
        System.out.println(list);
        list.clear();
    }
}
